
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>管理员管理界面</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<!-- https://fonts.google.com/specimen/Roboto -->
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<!-- https://fontawesome.com/ -->
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<!-- https://getbootstrap.com/ -->
<link rel="stylesheet" href="../css/templatemo-style.css">
<!--
	Product Admin CSS Template
	https://templatemo.com/tm-524-product-admin
	-->
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
		let re = new RegExp("\s?" + "username" + "=([^;]+)(;|$)")
		var username=document.cookie.match(re)[1];
	
		var arry;
		function getAllUsers() {
            $.ajax({
                url: "http://localhost:8080/voting-system/getAllUser",
                type: "post",
                success:function (data) {
                	arry=data;
                    var tbhtml = "<table class=\"table table-hover tm-table-small tm-product-table\"><thead><tr><th scope=\"col\">&nbsp;</th><th scope=\"col\">用户名</th><th scope=\"col\">用户ID</th><th scope=\"col\">性别</th><th scope=\"col\">年龄</th><th scope=\"col\">电话</th><th scope=\"col\">&nbsp;</th></tr></thead><tbody>";
                    for(var i = 0;i<data.length;i++){
                    	var j=i+1;
                    	tbhtml += "<tr><th scope=\"row\"><input type=\"radio\" name=\"user\" value=\""+data[i].user_id+"\"/></th><td class=\"tm-product-name\">"+data[i].username+"</td><td>"+data[i].user_id+"</td><td>"+data[i].sex+"</td><td>"+data[i].age+"</td><td>"+data[i].telephone+"</td></tr>";
                    }
                        tbhtml += "</tbody></table>";
                	$("#allUser").html(tbhtml);
                },
                dataType: "json"
            });
           
        }
		function updateUser() {
			var value="";
			var radio=document.getElementsByName("user");
			for(var i=0;i<radio.length;i++){
				if(radio[i].checked==true){
					value=radio[i].value;
					break;
				}
			}
			if(value==""){
				alert("请选择要修改的用户！")
			}else{
				document.cookie = 'user_id='+value+';'
				window.location.href='update-user.html'
			}
        }
</script>
<body id="reportsPage" onload="getAllUsers()">
	<nav class="navbar navbar-expand-xl">
		<div class="container h-100">
			<a class="navbar-brand" href="index.html">
				<h1 class="tm-site-title mb-0">用户管理</h1>
			</a>
			<button class="navbar-toggler ml-auto mr-0" type="button"
				data-toggle="collapse" data-target="#navbarSupportedContent"
				aria-controls="navbarSupportedContent" aria-expanded="false"
				aria-label="Toggle navigation">
				<i class="fas fa-bars tm-nav-icon"></i>
			</button>

			<div class="collapse navbar-collapse" id="navbarSupportedContent">
				<ul class="navbar-nav mx-auto h-100">
					<li class="nav-item"><a class="nav-link" href="result.jsp">
							<i class="fas fa-tachometer-alt"></i> 投票结果 <span class="sr-only">(current)</span>
					</a></li>
					<li class="nav-item dropdown"><a class="nav-link active"
						href="update.html"> <i class="far fa-file-alt"></i> <span>用户管理
						</span>
					</a></li>
					<li class="nav-item"><a class="nav-link dropdown-toggle"
						href="manage.html"> <i class="fas fa-shopping-cart"></i> 投票管理
					</a></li>

					<li class="nav-item"><a class="nav-link" href="center.html">
							<i class="far fa-user"></i> 个人中心
					</a></li>

				</ul>
				<ul class="navbar-nav">
					<li class="nav-item"><a class="nav-link d-block"
						href="../login.html"> <b>退出登录</b>
					</a></li>
				</ul>
			</div>
		</div>
	</nav>
	<form action="" method="post">
	<div class="container mt-5" style="position: relative; left: 170px">
		<div class="row tm-content-row">
			<div class="col-sm-12 col-md-12 col-lg-8 col-xl-8 tm-block-col">
				<div class="tm-bg-primary-dark tm-block tm-block-products">

					<div class="tm-product-table-container" id="allUser">
						<!--  <table class="table table-hover tm-table-small tm-product-table">
							<thead>
								<tr>
									<th scope="col">&nbsp;</th>
									<th scope="col">姓名</th>
									<th scope="col">用户ID</th>
									<th scope="col">性别</th>
									<th scope="col">年龄</th>
									<th scope="col">电话</th>
									<th scope="col">&nbsp;</th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">1</td>
									<td>1,450</td>
									<td>550</td>
									<td>28 March 2019</td>
									<td>55</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">2</td>
									<td>1,250</td>
									<td>750</td>
									<td>21 March 2019</td>
									<td>55</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">3</td>
									<td>1,100</td>
									<td>900</td>
									<td>18 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">4</td>
									<td>1,400</td>
									<td>600</td>
									<td>24 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">5</td>
									<td>1,800</td>
									<td>200</td>
									<td>22 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">6</td>
									<td>1,000</td>
									<td>1,000</td>
									<td>20 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">7</td>
									<td>500</td>
									<td>100</td>
									<td>10 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>
								<tr>
									<th scope="row"><input type="radio" name="user" /></th>
									<td class="tm-product-name">8</td>
									<td>1,000</td>
									<td>600</td>
									<td>08 Feb 2019</td>
									<td>900</td>

									<td><a href="#" class="tm-product-delete-link"> <i
											class="far fa-trash-alt tm-product-delete-icon"></i>
									</a></td>
								</tr>



							</tbody>
						</table>-->
					</div>

					<button type="button" class="btn btn-primary btn-block text-uppercase" onclick="updateUser()">
						修改</button>

				</div>
			</div>
	</form>


	<script src="../js/jquery-3.3.1.min.js"></script>
	<!-- https://jquery.com/download/ -->
	<script src="../js/bootstrap.min.js"></script>
	<!-- https://getbootstrap.com/ -->
	<!--  <script>
		$(function() {
			$(".tm-product-name").on("click", function() {
				window.location.href = "edit-product.html";
			});
		});
	</script>-->
</body>
</html>